import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '@/views/Login/LoginIndex.vue'
// import Forget from '@/views/Login/forgetIndex.vue'
// import Register from '@/views/Login/registerIndex.vue'
// import Useredit from '@/views/User/userEdit.vue'
// import editPassword from '@/views/User/editPassword.vue'
// import userDiary from '@/views/Diary/userDiary.vue'
// import addDiary from '@/views/Diary/addDiary.vue'
// import editDiary from '@/views/Diary/editDiary.vue'
// import statistics from '@/views/Home/statistics-tongji.vue'
// import recycle from '@/views/Home/recycle-huishou.vue'
// import set from '@/views/Home/set-shezhi.vue'
import { getToken } from '../utils/locaToken.js'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Home/homeIndex.vue'),
    name: 'Home'
  },
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Login/LoginIndex.vue'),
    name: 'login'
  },
  {
    path: '/forget',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Login/forgetIndex.vue'),
    name: 'forget'
  },
  {
    path: '/register',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Login/registerIndex.vue'),
    name: 'register'
  },
  {
    path: '/useredit',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/User/userEdit.vue'),
    name: 'useredit'
  },
  {
    path: '/pwdedit',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/User/editPassword.vue'),
    name: 'pwdedit'
  },
  {
    path: '/userdiary',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Diary/userDiary.vue'),
    name: 'userdiary'
  },
  {
    path: '/addDiary',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Diary/addDiary.vue'),
    name: 'addDiary'
  },
  {
    path: '/editDiary',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Diary/editDiary.vue'),
    name: 'editDiary'
  },
  {
    path: '/statistics',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Home/statistics-tongji.vue'),
    name: 'statistics'
  },
  {
    path: '/recycle',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Home/recycle-huishou.vue'),
    name: 'recycle'
  },
  {
    path: '/set',
    component: () => import(/* webpackChunkName: "group-foo" */ '@/views/Home/set-shezhi.vue'),
    name: 'set'
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // store.state.isLogin = !!localStorage.getItem('RIJI_USER')
  // console.log(store.state.isLogin)

  if (to.path === '/login' || to.path === '/forget' || to.path === '/register') {
    next()
  } else {
    if (getToken() === null || getToken() === '') {
      next('/login')
    } else {
      next()
    }
  }
})
export default router
